<template>
  <div>
    <Breadcrumb>
      <BreadcrumbItem>首页</BreadcrumbItem>
      <BreadcrumbItem>上下货查询</BreadcrumbItem>
    </Breadcrumb>
    <Form ref="formInline" :model="request" inline>
      <FormItem>
        上货员: <Select clearable  style="width: 120px;">
        <Option value="0">正常</Option>
        <Option value="0">报警</Option>
      </Select>
      </FormItem>
      <FormItem>
        设备名称：<Input
        type="text"
        v-model="params.device_name"
        clearable
        placeholder="设备名称"
        style="width: 120px"
      />
      </FormItem>
      <FormItem>
        设备编号: <Input
        type="text"
        v-model="params.device_id "
        clearable
        placeholder="设备编号"
        style="width: 120px"
      />
      </FormItem>
      <FormItem>
        时间查询: <DatePicker
        type="daterange"
        @on-change="timechange"
        :transfer="true"
        placement="bottom-end"
        placeholder="请选择开始-结束时间"
        style="width: 200px"
      ></DatePicker>
      </FormItem>

      <FormItem>
        <Button type="primary" @click="search" style="margin-right: 10px"
        >搜索</Button
        >
        <Button type="success" @click="search" style="margin-right: 10px"
        >导出</Button
        >
      </FormItem>
    </Form>
    <div>
      <Table :columns="columns1" :data="tableData" :height="height">
        <template slot-scope="{ row }" slot="status">
          <span class="success" v-if="row.status === '1'">正常</span>
          <span class="error" v-else>异常</span>
        </template>
        <template slot-scope="{ row }" slot="order_name">
          <span>{{ row.order_name[0] }}</span>
        </template>
        <template slot-scope="{ row }" slot="is_push">
          <span class="success" v-if="row.is_push == 2">完成</span>
          <span class="error" v-else>未完成</span>
        </template>
        <template slot-scope="{ row }" slot="option">
          <Button
            type="primary"
            size="small"
            style="margin-right: 5px"
            v-hasPermission="['37']"
            @click="add2"
          >查看上货详情</Button>
        </template>
      </Table>
    </div>
    <div style="display: flex; justify-content: center; margin-top: 24px">
      <Page
        background
        layout="prev, pager, next"
        :page-size="params.limit"
        :total="total"
        @on-change="handleCurrentChange"
        :current-page="params.page"
      />
      <Modal v-model="modal2"    :mask-closable="false" width="1000" >
        <Form :label-width="110">
          <div><h4 class="door_device">上货详情</h4></div>
          <Form ref="formInline" :model="request" inline>
            <FormItem>
              <Button type="primary" @click="search" style="margin-right: 10px">导出</Button>
            </FormItem>
            <Table border :columns="columns2" :data="data2"></Table>
            <div style="display: flex;justify-content: center;margin-top: 24px;">
              <Page :total="page.count" :page-size="20" :page-size-opts="[20,30,40,50,100]" show-elevator show-sizer
                    show-total @on-change="handleCurrentChange" @on-page-size-change="handleSizeChange" />
            </div>
          </Form>
        </Form>
      </Modal>
      <Modal v-model="modal3"    :mask-closable="false" width="1000" >
        <Form :label-width="110">
          <div><h4 class="door_device">库存详情</h4></div>
          <Form ref="formInline" :model="request" inline>
            <FormItem>
              <DatePicker
                type="daterange"
                @on-change="timechange"
                :transfer="true"
                placement="bottom-end"
                placeholder="请选择开始-结束时间"
                style="width: 200px"
              ></DatePicker>
            </FormItem>
            <FormItem>
              <Button type="primary" @click="search" style="margin-right: 10px">搜索</Button>
              <Button type="primary" @click="search" style="margin-right: 10px">导出</Button>
              <Button type="success" style="margin-right: 10px">完成标准库存设置</Button>
              <Button type="error" style="margin-right: 10px">取消</Button>
            </FormItem>
            <div><p>剩余库存总数</p></div>
            <Table border :columns="columns2" :data="data2"></Table>
            <div style="display: flex;">
              <div><p>库存更新日志:</p></div>
              <div>
                <p>2011-09-16 17：55：19上货 未更新库存 </p>
                <p>2011-09-16 17：55：19上货 未更新库存 </p>
                <p>2011-09-16 17：55：19上货 未更新库存 </p>
                <p>2011-09-16 17：55：19上货 未更新库存 </p>
                <p>2011-09-16 17：55：19上货 未更新库存 </p>
                <p>2011-09-16 17：55：19上货 未更新库存 </p>
              </div>
            </div>
          </Form>
        </Form>
      </Modal>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        columns2: [
          {
            title: '商品名称',
            key: 'name'
          },
          {
            title: '上货状态',
            key: 'age'
          },
          {
            title: '数量',
            key: 'address'
          }
        ],
        data2: [
          {
            name: '香飘飘奶茶原味杯装80g',
            age: '减少',
            address: '-4'
          },
          {
            name: '康师傅冰紅茶柠檬味瓶装500ml .',
            age: '新增',
            address: '+4'
          },
          {
            name: '康师傅冰糖雪梨500ml',
            age: '减少',
            address: '-4'
          },
          {
            name: '农夫山泉茶m柠檬红茶瓶装500ml',
            age: '新增',
            address: '+4'
          }
        ],
        params: {
          create_time: [],
          user_id: "",
          device_name: "",
          device_id: "",
          page: 1,
          limit: 10,
        },
        total: 0,
        page: {},
        height: this.$store.state.height,
        modal1: false,
        modal2: false,
        modal3: false,
        data1: [
          {
            id: 1,
            title: "机器组3",
          },
          {
            id: 2,
            title: "机器组4",
          },
        ],
        request: {
          device_number:"",
          page: 1,
        },
        columns1: [
          {
            title: "活动编号",
            key: "activity_id",
            minWidth: 150,
            align: "center",
          },
          {
            title: "姓名",
            key: "username",
            minWidth: 300,
            align: "center",
          },
          {
            title: "设备编号",
            key: "device_id",
            minWidth: 150,
            align: "center",
          },

          {
            title: "所属门店",
            key: "shop_name",
            minWidth: 150,
            align: "center",
          },
          {
            title: "创建时间",
            key: "create_time",
            minWidth: 150,
            align: "center",
          },
          {
            title: "库存状态",
            key: "status",
            minWidth: 150,
            align: "center",
          },
          {
            title: "操作",
            slot: "option",
            minWidth: 150,
            align: "center",
          }
        ],
        tableData: [],
        role_id:null,
      };
    },
    mounted() {

      this.init();
    },
    methods: {
      add2(){
        this.cancel();
        this.modal2 = true
        this.allocated = [];
        this.undistributed = [];
        if(this.infoID == 6){
          console.log('6')
          this.axios.post("device/getAllDev").then(res => {
            if (res.code == 1) {
              this.allocated = res.data.allocated;
              this.undistributed= res.data.undistributed;
            }
          });

        }
      },
      add3(){
        this.cancel();
        this.modal3 = true
        this.allocated = [];
        this.undistributed = [];
        if(this.infoID == 6){
          console.log('6')
          this.axios.post("device/getAllDev").then(res => {
            if (res.code == 1) {
              this.allocated = res.data.allocated;
              this.undistributed= res.data.undistributed;
            }
          });

        }
      },
      init() {
        this.axios.post("Store/up_list", this.params).then((res) => {
          console.log("this.params: ", this.params);
          if (res.code == 1) {
            console.log(res);
            this.total = res.data.count;
             this.params.total = res.data.count
          this.params.curPage = res.data.curPage // 当前页
          this.params.countPage = res.data.countPage // 总页数
            this.tableData = res.data.list;

          }
        });
      },

      search() {
        this.params.page = 1;
        this.init();
      },
      confirm() {
        this.modal1 = false;
        this.$Message.success("保存成功！");
        this.cancel();
      },
      cancel() {},
      add() {
        this.modal1 = true;
      },
      setStatus(id, status) {
        var text = "确定要" + (status == 1 ? "启用" : "禁用") + "此机器组么？";
        this.$Modal.confirm({
          title: text,
          onOk: () => {
            this.$Message.success("操作成功");
          },
          onCancel: () => {},
        });
      },
      lists() {},
      timechange(val) {
        console.log(val);
      },
      handleSizeChange(val) {
        this.request.page = 1;
        this.request.limit = val;
        this.lists();
      },
      handleCurrentChange(val) {
        this.params.page = val;
        this.init();
      },
    },
  };
</script>

<style>
  *{
    margin: 0;
    padding: 0;
  }
  .door_device{
    position: relative;
    top: -20px;
  }
</style>
